import React from 'react';

class Pagination extends React.Component {

    constructor(props) {
        super(props);
    }

    render() {

        const totalPage = Math.ceil(this.props.totalRows / this.props.pageSize);
        return (
            <div className="clearfix">
                <ul className="pagination">
                    <li className={this.props.currentPage == 1?'active':''}>
                        <a href="javascript:void(0)"
                           onClick={()=>this.props.currentPage > 1 && this.props.loader(1)}>首页</a>
                    </li>
                    {this.props.currentPage > 1 ?
                        <li><a href="javascript:void(0)"
                               onClick={()=>this.props.loader(this.props.currentPage - 1)}>上一页</a></li> : null}
                    {this.props.currentPage < totalPage ?
                        <li><a href="javascript:void(0)"
                               onClick={()=>this.props.loader(this.props.currentPage + 1)}>下一页</a></li> : null}
                    {this.props.totalPage > 1 ?
                        <li className={this.props.currentPage==totalPage?'active':''}><a href="javascript:void(0)"
                                                                                         onClick={()=>this.props.currentPage<totalPage&&this.props.loader(totalPage)}>末页</a>
                        </li> : null}
                </ul>
            </div>
        )
    }
}

Pagination.propTypes = {
    pageSize: React.PropTypes.number.isRequired,
    loader: React.PropTypes.func.isRequired,
    totalRows: React.PropTypes.number.isRequired,
    currentPage: React.PropTypes.number.isRequired
};

export default Pagination;